package zpp_nape.shape;
import zpp_nape.Config;
import zpp_nape.Const;
import zpp_nape.util.Flags;
import DummyNapeMain;
import zpp_nape.util.Math;
import zpp_nape.util.Names;
import zpp_nape.util.Pool;
import zpp_nape.util.Lists;
import zpp_nape.shape.Circle;
import zpp_nape.space.Space;
import zpp_nape.shape.Polygon;
import zpp_nape.shape.Shape;
import zpp_nape.phys.FeatureMix;
import zpp_nape.phys.FluidProperties;
import zpp_nape.phys.Material;
import zpp_nape.phys.Body;
import zpp_nape.geom.AABB;
import zpp_nape.geom.Distance;
import zpp_nape.geom.Mat23;
import zpp_nape.geom.Vec2;
import zpp_nape.geom.VecMath;
import zpp_nape.geom.Collide;
import zpp_nape.dynamics.Arbiter;
import zpp_nape.dynamics.Contact;
import zpp_nape.dynamics.InteractionFilter;
import zpp_nape.constraint.Constraint;
import zpp_nape.dynamics.SpaceArbiterList;
import zpp_nape.constraint.Matrices;
import zpp_nape.constraint.PivotJoint;
import zpp_nape.constraint.WeldJoint;
import nape.util.Flags;
import nape.util.Lists;
import nape.util.Debug;
import nape.space.Space;
import nape.shape.Circle;
import nape.shape.Polygon;
import nape.shape.Edge;
import nape.shape.Shape;
import nape.phys.FluidProperties;
import nape.phys.Material;
import nape.phys.Body;
import nape.geom.AABB;
import nape.geom.Geom;
import nape.geom.Mat23;
import nape.geom.Vec2;
import nape.dynamics.Contact;
import nape.dynamics.Arbiter;
import nape.dynamics.InteractionFilter;
#if swc@:keep#end class ZPP_Edge{
    static public var zpp_pool:ZPP_Edge;
    public var next:ZPP_Edge;
    #if(flash9&&flib)@:ns("flibdel")#end public inline function free(){
        polygon=null;
    }
    public var polygon:ZPP_Polygon;
    static public var internal:Bool;
    public var outer:Edge;
    #if(flash9&&flib)@:ns("flibdel")#end public inline function wrapper(){
        if(outer==null){
            internal=true;
            outer=new Edge();
            internal=false;
            outer.zpp_inner=this;
        }
        return outer;
    }
    public var lnormx:Float;
    public var lnormy:Float;
    public var wrap_lnorm:Vec2;
    public var gnormx:Float;
    public var gnormy:Float;
    public var wrap_gnorm:Vec2;
    public var length:Float;
    public var lprojection:Float;
    public var gprojection:Float;
    public function get_lnorm(){
        var me=this;
        wrap_lnorm=new Vec2(lnormx,lnormy);
        wrap_lnorm.zpp_inner.immutable=true;
        wrap_lnorm.zpp_inner._validate=function(){
            if(me.polygon==null)throw "Error: Edge not currently in use";
            me.polygon.validate_laxi();
            {
                me.wrap_lnorm.zpp_inner.x=me.lnormx;
                me.wrap_lnorm.zpp_inner.y=me.lnormy;
                {
                    #if NAPE_ASSERT var res={
                        !({
                            #if flash9 var ret:Bool=untyped __global__["isNaN"](me.wrap_lnorm.zpp_inner.x);
                            ret;
                            #else Math.isNaN(me.wrap_lnorm.zpp_inner.x);
                            #end
                        });
                    };
                    if(!res)throw "assert("+"!assert_isNaN(me.wrap_lnorm.zpp_inner.x)"+") :: "+("vec_set(in n: "+"me.wrap_lnorm.zpp_inner."+",in x: "+"me.lnormx"+",in y: "+"me.lnormy"+")");
                    #end
                };
                {
                    #if NAPE_ASSERT var res={
                        !({
                            #if flash9 var ret:Bool=untyped __global__["isNaN"](me.wrap_lnorm.zpp_inner.y);
                            ret;
                            #else Math.isNaN(me.wrap_lnorm.zpp_inner.y);
                            #end
                        });
                    };
                    if(!res)throw "assert("+"!assert_isNaN(me.wrap_lnorm.zpp_inner.y)"+") :: "+("vec_set(in n: "+"me.wrap_lnorm.zpp_inner."+",in x: "+"me.lnormx"+",in y: "+"me.lnormy"+")");
                    #end
                };
            };
        }
    }
    public function get_gnorm(){
        var me=this;
        wrap_gnorm=new Vec2(gnormx,gnormy);
        wrap_gnorm.zpp_inner.immutable=true;
        wrap_gnorm.zpp_inner._validate=function(){
            if(me.polygon==null)throw "Error: Edge not currently in use";
            if(me.polygon.body==null)throw "Error: Edge worldNormal only makes sense if the parent Polygon is contained within a rigid body";
            me.polygon.validate_gaxi();
            {
                me.wrap_gnorm.zpp_inner.x=me.gnormx;
                me.wrap_gnorm.zpp_inner.y=me.gnormy;
                {
                    #if NAPE_ASSERT var res={
                        !({
                            #if flash9 var ret:Bool=untyped __global__["isNaN"](me.wrap_gnorm.zpp_inner.x);
                            ret;
                            #else Math.isNaN(me.wrap_gnorm.zpp_inner.x);
                            #end
                        });
                    };
                    if(!res)throw "assert("+"!assert_isNaN(me.wrap_gnorm.zpp_inner.x)"+") :: "+("vec_set(in n: "+"me.wrap_gnorm.zpp_inner."+",in x: "+"me.gnormx"+",in y: "+"me.gnormy"+")");
                    #end
                };
                {
                    #if NAPE_ASSERT var res={
                        !({
                            #if flash9 var ret:Bool=untyped __global__["isNaN"](me.wrap_gnorm.zpp_inner.y);
                            ret;
                            #else Math.isNaN(me.wrap_gnorm.zpp_inner.y);
                            #end
                        });
                    };
                    if(!res)throw "assert("+"!assert_isNaN(me.wrap_gnorm.zpp_inner.y)"+") :: "+("vec_set(in n: "+"me.wrap_gnorm.zpp_inner."+",in x: "+"me.gnormx"+",in y: "+"me.gnormy"+")");
                    #end
                };
            };
        }
    }
    public function new(){
        {
            lnormx=0;
            lnormy=0;
            {
                #if NAPE_ASSERT var res={
                    !({
                        #if flash9 var ret:Bool=untyped __global__["isNaN"](lnormx);
                        ret;
                        #else Math.isNaN(lnormx);
                        #end
                    });
                };
                if(!res)throw "assert("+"!assert_isNaN(lnormx)"+") :: "+("vec_set(in n: "+"lnorm"+",in x: "+"0"+",in y: "+"0"+")");
                #end
            };
            {
                #if NAPE_ASSERT var res={
                    !({
                        #if flash9 var ret:Bool=untyped __global__["isNaN"](lnormy);
                        ret;
                        #else Math.isNaN(lnormy);
                        #end
                    });
                };
                if(!res)throw "assert("+"!assert_isNaN(lnormy)"+") :: "+("vec_set(in n: "+"lnorm"+",in x: "+"0"+",in y: "+"0"+")");
                #end
            };
        };
        {
            gnormx=0;
            gnormy=0;
            {
                #if NAPE_ASSERT var res={
                    !({
                        #if flash9 var ret:Bool=untyped __global__["isNaN"](gnormx);
                        ret;
                        #else Math.isNaN(gnormx);
                        #end
                    });
                };
                if(!res)throw "assert("+"!assert_isNaN(gnormx)"+") :: "+("vec_set(in n: "+"gnorm"+",in x: "+"0"+",in y: "+"0"+")");
                #end
            };
            {
                #if NAPE_ASSERT var res={
                    !({
                        #if flash9 var ret:Bool=untyped __global__["isNaN"](gnormy);
                        ret;
                        #else Math.isNaN(gnormy);
                        #end
                    });
                };
                if(!res)throw "assert("+"!assert_isNaN(gnormy)"+") :: "+("vec_set(in n: "+"gnorm"+",in x: "+"0"+",in y: "+"0"+")");
                #end
            };
        };
        length=0;
        lprojection=0;
        gprojection=0;
    }
}
